package client.gui;

import java.awt.*;

import client.Client;
import client.game.world.map.Region;

public class GameCanvas extends Canvas {

	private static final long serialVersionUID = -3332219929893286109L;
	private Image buffer;
	private Graphics bufferGraphics;
	private int regionX, regionY; //TODO - save in local player info
	
	@Override
	public void paint(Graphics g) {
		if(bufferGraphics == null) {
			buffer = createImage(getWidth(), getHeight());
			bufferGraphics = buffer.getGraphics();
		}
		drawGame();
		g.drawImage(buffer, 0, 0, this);
		g.dispose();
	}
	
	@Override
	public void update(Graphics g) {
		paint(g);
	}
	
	public void drawGame() {
		bufferGraphics.clearRect(-5,-5, getWidth()+5, getHeight()+5);
		bufferGraphics.translate(Client.getPlayer().getRegionOffsetX(), Client.getPlayer().getRegionOffsetY()); //Move the display for the current player region offset
		Client.getWorld().getWorldMap().getRegion(regionX, regionY).drawRegion(bufferGraphics);
		//drawEntities();
		bufferGraphics.translate(-Client.getPlayer().getRegionOffsetX(), -Client.getPlayer().getRegionOffsetY()); //Back to normal drawing
	}
	
	public void drawMap() {
		Region region = Client.getWorld().getWorldMap().getRegion(regionX, regionY);
		region.drawRegion(bufferGraphics);
	}
}
